<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>登录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit">
    <meta name="referrer" content="never">
    <meta name="robots" content="noindex, nofollow">
    {include file="store/common/mate" /}
</head>

<style>
    body {
        padding: 0;
        margin: 0;
    }

    .login-wrap {
        box-sizing: border-box;
        width: 100%;
        height: 100%;
        padding-top: 10%;
        background-image: url();
        /* background-color: #112346; */
        background-repeat: no-repeat;
        background-position: center right;
        background-size: 100%;
    }

    .login-container {
        border-radius: 10px;
        margin: 0px auto;
        width: 350px;
        padding: 30px 35px 15px 35px;
        background: #fff;
        border: 1px solid #eaeaea;
        text-align: left;
        box-shadow: 0 0 20px 2px rgba(0, 0, 0, 0.1);
    }

    .title {
        margin: 0px auto 40px auto;
        text-align: center;
        color: #505458;
    }
</style>
<body>

<div class="login-wrap" id="app">
    <el-form class="login-container">
        <h1 class="title">用户登陆</h1>
        <el-form-item>
            <el-input type="text" v-model="username" placeholder="用户账号" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
            <el-input type="password" v-model="password" placeholder="用户密码" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="doLogin" @keyup.enter="keyDown(e)" style="width: 100%;">登陆</el-button>
        </el-form-item>
    </el-form>
</div>

<script>
    new Vue({
        el: '#app',
        data: function () {
            return {
                username: '',
                password: '',
            }
        },
        created() {
        },
        mounted() {
            // 绑定监听事件
            window.addEventListener("keydown", this.keyDown);
        },
        destroyed() {
            // 销毁事件
            window.removeEventListener("keydown", this.keyDown, false);
        },
        methods: {
            keyDown(e) {
                // 回车则执行登录方法 enter键的ASCII是13
                if (e.keyCode === 13) {
                    this.doLogin(); // 定义的登录方法
                }
            },
            doLogin() {
                if (!this.username) {
                    this.$message({
                        type: 'error',
                        message: '请输入账号'
                    });
                    return false
                }
                if (!this.password) {
                    this.$message({
                        type: 'error',
                        message: '请输入密码'
                    });
                    return false
                }
                let params = {}
                params.username = this.username
                params.password = this.password
                post('', params).then(res => {
                    this.$message({
                        type: res.code == 1 ? 'success' : 'error',
                        message: res.msg
                    });
                    if (res.code) {
                        localStorage.setItem("token", res.data.token);
                        window.location.href = res.url
                    }
                })
            },
        }
    })
</script>

</body>
</html>
